<?php
namespace Admin\Controller;
use Think\Controller;
class HelpController extends Controller
{
	//帮助中心列表
	public function helpList()
	{
		$helpModel = M('help');
		//$classModel = M('help_class');
		$count = $helpModel->count();
		$Page  = new \Think\Page($count,1);
		$show = $Page->show();
		$helpList = $helpModel->join('help_class ON help.help_class_id = help_class.id')->field('help.id as id,name,status,time,content')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('helpList',$helpList);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
	}
	//添加帮助信息
	public function helpAddList()
	{
		$classModel = M('help_class');
		$this->classList = $classModel->select();
		$this->display();
	}
	//修改列表
	public function helpResetList()
	{
		$id = $_GET['id'];
		$helpModel = M('help');
		$classModel = M('help_class');
		$helpList = $helpModel->where('help.id="'.$id.'"')->find();
		$this->classList = $classModel->select();
		$this->assign('help',$helpList);
		$this->display();
	}
	//内容的添加或修改
	public function helpSave()
	{
		$data['content'] = $_POST['content'];
		$data['status'] = $_POST['status'];
		$data['help_class_id'] = $_POST['help_class_id'];
		$helpModel = D('help');
		if (isset($_GET['id'])) {
			$id = $_GET['id'];
			$result = $helpModel->where('id="'.$id.'"')->save($data);
			if ($result) {
				$this->success('修改成功','./helpList');
			}else{
				$this->error('修改失败');
			}
		}else{
			$result = $helpModel->add($data);
			if ($result) {
				$this->success('添加成功','./helpList');
			}else{
				$this->error('添加失败');
			}
		}
	}
	//删除帮助信息
	public function helpDelete()
	{
		$id = $_GET['id'];
		$data = M('help');
		$result = $data->where('id="'.$id.'"')->delete();
		if ($result) {
			$this->success('删除成功','./helplist');
		}else{
			$this->error('删除失败');
		}
	}
	//帮助中心分类列表
	public function helpClassList()
	{
		$classModel = M('help_class');
		$this->classList = $classModel->select();
		$this->display();
	}
	//添加帮助中心分类列表
	public function classAddList()
	{
		$this->display();
	}
	//帮助中心分类修改列表
	public function classResetList()
	{
		$id = $_GET['id'];
		$classModel = M('help_class');
		$class = $classModel->where('id="'.$id.'"')->find();
		$this->assign('class',$class);
		$this->display();
	}
	//保存分类
	public function classSave()
	{
		$data['name'] = $_POST['name'];
		$classModel = M('help_class');
		if (isset($_GET['id'])) {
			$id = $_GET['id'];
			$result = $classModel->where('id="'.$id.'"')->save($data);
			if ($result) {
				$this->success('修改成功','./helpClassList');
			}else{
				$this->error('修改失败');
			}
		}else{
			$result = $classModel->add($data);
			if ($result) {
				$this->success('添加成功','./helpClassList');
			}else{
				$this->error('添加失败');
			}
		}
	}
	//删除分类
	public function classDelete()
	{
		$id = $_GET['id'];
		$data = M('help_class');
		$result = $data->where('id="'.$id.'"')->delete();
		if ($result) {
			$this->success('删除成功','./helpClassList');
		}else{
			$this->error('删除失败');
		}
	}
}